
const app = getApp();
var funcs = require('../../static/js/funcs.js');

Page({
  data: {
    category_list: ['预约详情','我的客户','客户关系'],
    select_category: 0,
    bookinfos: [],
    yy_type:1,
    uList:[1,2]
  },

  dealbook(e){
    let bookid = e.currentTarget.dataset.bookid
    let openid = app.globalData.openid
    let that = this
    console.log(bookid)
    wx.showModal({
      title: '提示',
      content: '是否处理？',
      success(res) {
        if (res.confirm) {
          funcs.dealbook(openid,bookid).then(res=>{
            if(res.data.succeed){
              that.getBookList(that.data.status)
              console.log("处理成功")
              wx.showToast({
                title: '处理成功',
                icon:"success",
                duration:1000
              })
            }
          })
        }
      }
    })

  },

  dealAdd(e){
    let bookid = e.currentTarget.dataset.bookid
    let openid = app.globalData.openid
    let that = this
    console.log(bookid)
    wx.showModal({
      title: '提示',
      content: '是否处理？',
      success(res) {
        if (res.confirm) {
          wx.showToast({
            title: '该功能未开放',
            icon:"error",
            duration:1000
          })
        }
      }
    })

  },

  dealWechat(e){
    wx.showToast({
      title: '该功能未开放',
      icon:"error",
      duration:1000
    })
  },
  showidcard(e){
    let bookid = e.currentTarget.dataset.bookid
    console.log(bookid)
    this.setData({
      showidcard:bookid
    })
    console.log(this.data.showidcard)
  },
  unshowidcard(){
    this.setData({
      showidcard:null
    })
  },
  select_category:function(e){
    let index = e.currentTarget.dataset.category
    console.log(index)
    let that = this
    this.setData({
      select_category: index
    })
    let openid = app.globalData.openid //获取用户openid
    
    // console.log(index)
    // console.log(this.data.category_list[index])
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let openid = app.globalData.openid
    if(app.globalData.loginedFlag==false){
      this.setData({
        loginedFlag: false
      })
      wx.reLaunch({
        url: '/pages/my/my',
      })
      wx.showToast({
        title: "请先绑定",
        icon: 'none',
        duration: 2000
      })
      return
    }
    funcs.judgeStaff(openid).then(res=>{
      if(res.data.succeed){
        console.log("该员工已注册")
        app.globalData.loginedFlag = true
        this.setData({
          loginedFlag: true,
          status:99
        })
        this.getBookList(99)
      }else{
        app.globalData.loginedFlag = false
        this.setData({
          loginedFlag: false
        })
        wx.reLaunch({
          url: '/pages/my/my',
        })
        wx.showToast({
          title: "请先绑定",
          icon: 'none',
          duration: 2000
        })
      }
    })
  },
  getBookList(status){
    let staffid = app.globalData.openid
    let that = this
    funcs.getBooksByStaff(staffid,status).then(res=>{
      if(res.data.succeed){
        console.log(res.data.data.books)
        that.setData({
          books: res.data.data.books
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if(app.globalData.loginedFlag==false){
      this.setData({
        loginedFlag: false
      })
      wx.reLaunch({
        url: '/pages/my/my',
      })
      wx.showToast({
        title: "请先绑定",
        icon: 'none',
        duration: 2000
      })
      return
    }
    this.getBookList(this.data.status==null? 99:this.data.status)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  radioChange(e) {
    let openid = app.globalData.openid
    let value = e.detail.value;
    this.setData({
      status: value=="done"? 1: 99,
      yy_type: value=="done"? 2:1
    })
    this.getBookList(this.data.status)
  },
  call_phone: function (res) {
    let data = res.currentTarget.dataset
    wx.showModal({
      title: "提示",
      content: "拨打 " + data.telephone + " ?",
      complete: (res) => {
        if (res.cancel) {
          return
        }
        if (res.confirm) {
          wx.makePhoneCall({
            phoneNumber: data.telephone,
            success: function () {
              console.log("拨打电话成功！")
            },
            fail: function () {
              console.log("拨打电话失败！")
            }
          })
        }
      }
    })
  },
})
